001 /*
002 * Copyright 2004 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.metro.info;
020
021 import net.dpml.lang.Enum;
022
023 /**
024 * Collection policy enummeration.
025 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
026 * @version 1.0.1
027 */
028 public final class CollectionPolicy extends Enum
029 {
030 //-------------------------------------------------------------------
031 // static
032 //-------------------------------------------------------------------
033
034 /**
035 * Serial version identifier.
036 */
037 static final long serialVersionUID = 1L;
038
039 /**
040 * Weak collection policy.
041 */
042 public static final CollectionPolicy WEAK = new CollectionPolicy( "weak" );
043
044 /**
045 * Soft collection policy.
046 */
047 public static final CollectionPolicy SOFT = new CollectionPolicy( "soft" );
048
049 /**
050 * Hard collection policy.
051 */
052 public static final CollectionPolicy HARD = new CollectionPolicy( "hard" );
053
054 /**
055 * Collection policy to be established at system discretion.
056 */
057 public static final CollectionPolicy SYSTEM = new CollectionPolicy( "system" );
058
059 /**
060 * Array of static activation policy enumeration values.
061 */
062 private static final CollectionPolicy[] ENUM_VALUES =
063 new CollectionPolicy[]{WEAK, SOFT, HARD, SYSTEM};
064
065 /**
066 * Returns an array of activation enum values.
067 * @return the activation policies array
068 */
069 public static CollectionPolicy[] values()
070 {
071 return ENUM_VALUES;
072 }
073
074 /**
075 * Internal constructor.
076 * @param label the enumeration label.
077 */
078 private CollectionPolicy( String label )
079 {
080 super( label );
081 }
082
083 /**
084 * Parse the supplied name.
085 * @param value the value to parse
086 * @return the collection policy
087 */
088 public static CollectionPolicy parse( String value )
089 {
090 if( value.equalsIgnoreCase( "hard" ) )
091 {
092 return HARD;
093 }
094 else if( value.equalsIgnoreCase( "soft" ) )
095 {
096 return SOFT;
097 }
098 else if( value.equalsIgnoreCase( "weak" ) )
099 {
100 return WEAK;
101 }
102 else if( value.equalsIgnoreCase( "system" ) )
103 {
104 return SYSTEM;
105 }
106 else
107 {
108 final String error =
109 "Unrecognized collection policy argument [" + value + "]";
110 throw new IllegalArgumentException( error );
111 }
112 }
113 }